package com.ruoyi.system.utils;

import lombok.extern.slf4j.Slf4j;

import java.net.InetAddress;
import java.net.UnknownHostException;


@Slf4j
public class IPCheck {


    public static boolean checkIp() {
        String allowedIp = "172.18.1.2";
        String externalIp = "";
        try {
            externalIp = InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException e) {
            log.error("获取内网IP地址失败", e);
            return false;
        }
        if (!externalIp.equals(allowedIp)) {
            log.info("外网IP地址不符合要求，退出定时任务。当前IP: " + externalIp);
            return false;
        }
        log.info("IP地址符合要求，继续执行.当前IP: " + externalIp);
        return true;
    }

}
